/**
 * Created by Administrator on 2017/5/26 0026.
 */
$(function () {

    var banner = $(".banner");
    banner.slide({
        mainCell:".banner_lun ul",
        autoPlay:"true",
        effect:"fade",
        delayTime:1500,
        trigger:"click",
        pnLoop:"true",
        titCell:".hd li",
        titOnClassName:"bannerOn",
        interTime:"4000"
    });
    banner.on({
        mouseenter:function () {
            $(this).find(".hd").show().end().find(".prev").show().end().find(".next").show()
        },
        mouseleave:function () {
            $(this).find(".hd").hide().end().find(".next").hide().end().find(".prev").hide()
        }
    });
    //请求数据做列表轮播图;
    $.ajax({
        url:"index.json",
        success:function (res) {
            // console.log(res);
            var arr = res;
            //先遍历大数组
            var parent = $(".list_ul");

            for (var j = 0; j<arr.length; j++){
                var temLi = '<li class="lun-news">';
                temLi += '<ul class="clear">';
                //遍历每一个小数组，将内容拼接成字符串，让浏览器渲染
                for (var i = 0; i < arr[j].length; i++){
                    // console.log(111);
                    var tempt = '<li>';
                    tempt += '<span class="ico">';
                    tempt += '<s class="'+ arr[j][i].hot +'" title="新品上架"></s>';
                    tempt +='<s class="'+ arr[j][i].free +'" title="包邮专区"></s>';
                    tempt +='</span>';
                    tempt += '<i class="li_top"></i>';
                    tempt += '<i class="li_left"></i>';
                    tempt += '<i class="li_bottom"></i>';
                    tempt += '<i class="li_right"></i>';
                    tempt += '<a href="#"><img src="'+ arr[j][i].imgSrc +'" alt=""></a>';
                    tempt += '<div class="li_price">';
                    tempt += '<p><a href="#">'+ arr[j][i].content +'</a></p>';
                    tempt += '<p class="fs14">'+ arr[j][i].price +'</p>';
                    tempt += '</div>';
                    tempt += '<div class="state">';
                    tempt += '<img src="'+ arr[j][i].statesImg +'" alt="">';
                    tempt += '<div>'+ arr[j][i].states +'</div>';
                    tempt += '</div>';
                    tempt += '</li>';
                    temLi += tempt;
                }
                temLi += '</ul>';
                temLi += '</li>';
                // console.log(temLi);
                parent.html(parent.html()+temLi);
            }
            // 给动态生成的结构绑上事件；
            var news = $(".news");
            news.slide({
                mainCell:".bd .list_ul",
                autoPlay:"true",
                effect:"leftLoop",
                delayTime:500,
                trigger:"click",
                pnLoop:"true",
                titCell:".hn_t li",
                titOnClassName:"dop_on",
                interTime:"5000"
            })
        }

    });
    $.ajax({
        url:"hots.json",
        success:function (res) {
            // console.log(res);
            var arr = res;
            //先遍历大数组
            var parent = $(".hots_ul");

            for (var j = 0; j<arr.length; j++){
                var temLi = '<li class="lun-news">';
                temLi += '<ul class="clear">';
                //遍历每一个小数组，将内容拼接成字符串，让浏览器渲染
                for (var i = 0; i < arr[j].length; i++){
                    // console.log(111);
                    var tempt = '<li>';
                    tempt += '<span class="ico">';
                    tempt += '<s class="'+ arr[j][i].hot +'" title="新品上架"></s>';
                    tempt +='<s class="'+ arr[j][i].free +'" title="包邮专区"></s>';
                    tempt +='</span>';
                    tempt += '<i class="li_top"></i>';
                    tempt += '<i class="li_left"></i>';
                    tempt += '<i class="li_bottom"></i>';
                    tempt += '<i class="li_right"></i>';
                    tempt += '<a href="#"><img src="'+ arr[j][i].imgSrc +'" alt=""></a>';
                    tempt += '<div class="li_price">';
                    tempt += '<p><a href="#">'+ arr[j][i].content +'</a></p>';
                    tempt += '<p class="fs14">'+ arr[j][i].price +'</p>';
                    tempt += '</div>';
                    tempt += '<div class="state">';
                    tempt += '<img src="'+ arr[j][i].statesImg +'" alt="">';
                    tempt += '<div>'+ arr[j][i].states +'</div>';
                    tempt += '</div>';
                    tempt += '</li>';
                    temLi += tempt;
                }
                temLi += '</ul>';
                temLi += '</li>';
                // console.log(temLi);
                parent.html(parent.html()+temLi);
            }
            // 给动态生成的结构绑上事件；
            var news = $(".hots");
            news.slide({
                mainCell:".bd .hots_ul",
                autoPlay:"true",
                effect:"leftLoop",
                delayTime:500,
                trigger:"click",
                pnLoop:"true",
                titCell:".hn_t li",
                titOnClassName:"dop_on",
                interTime:"5000"
            })
        }
    });
    var products = $(".products_lun");
    products.slide({
        mainCell:".bd ul",
        autoPlay:"true",
        effect:"leftLoop",
        delayTime:500,
        trigger:"click",
        pnLoop:"true",
        titCell:".hd li",
        titOnClassName:"dop_on",
        interTime:"4000"
    });
    products.on({
        mouseenter:function () {
            $(this).find(".hd").show().end().find(".Pprev").show().end().find(".Pnext").show()
        },
        mouseleave:function () {
            $(this).find(".hd").hide().end().find(".Pnext").hide().end().find(".Pprev").hide()
        }
    });

});
